package com.example.config;

import org.springframework.http.HttpStatus;

import java.io.Serializable;

public class ResponseVO<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    // HTTP状态码
    private HttpStatus status;
    // 响应消息
    private String message;
    // 响应数据
    private T data;

    // 构造函数
    public ResponseVO(HttpStatus status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public ResponseVO(HttpStatus status, String message) {
        this.status = status;
        this.message = message;
    }

    // 默认构造函数
    public ResponseVO() {}

    // 工厂方法，用于创建成功响应
    public static <T> ResponseVO<T> success(T data) {
        return new ResponseVO<>(HttpStatus.OK, "成功", data);
    }

    public static <T> ResponseVO<T> success(String message) {
        return new ResponseVO<>(HttpStatus.OK, message);
    }

    // 工厂方法，用于创建错误响应
    public static <T> ResponseVO<T> error(HttpStatus status, String message) {
        return new ResponseVO<>(status, message, null);
    }

    // getter和setter
    public HttpStatus getStatus() {
        return status;
    }

    public void setStatus(HttpStatus status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
